<h:form id="formOrcamento" 
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:pe="http://primefaces.org/ui/extensions"
        xmlns:f="http://java.sun.com/jsf/core">

    <script language="JavaScript" src = "scripts/script.js"/>

    <h:panelGrid style="width: 100%">

        <h:panelGrid columns="3" style="width: 100%">
            <h:panelGroup>
                <h:outputLabel value="Ficha de Despesa"/><br/>
                <p:inputText value="#{orcamentoBean.orcamento.fichaDespesa}" 
                             style="width: 100px"
                             readonly="true"/>
            </h:panelGroup>
            <h:panelGroup>
                <h:outputLabel value="Elemento" /><br/>
                <p:selectOneMenu value="#{orcamentoBean.orcamento.elementoDeDespesa}" 
                                 style="width: 138px" required="true">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{orcamentoBean.elementosDespesa}" />
                    <f:converter converterId="simpleEntityConverter" />
                </p:selectOneMenu>
            </h:panelGroup>
            <h:panelGroup>
                <h:outputLabel value="Categoria de Orçamento" /><br/>
                <p:selectOneMenu value="#{orcamentoBean.orcamento.categoriaOrcamento}" 
                                 style="width: 138px">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{orcamentoBean.categoriasOrcamento}" />
                    <f:converter converterId="simpleEntityConverter" />
                </p:selectOneMenu>
            </h:panelGroup>
        </h:panelGrid>
        <h:panelGrid columns="1" style="width: 100%">
            <h:panelGroup >
                <h:outputLabel value="Tipo de Despesa" /><br/>
                <p:selectOneMenu value="#{orcamentoBean.orcamento.tipoDespesa}" 
                                 style="width: 400px">

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{orcamentoBean.tiposDespesa}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="valorDespesa leiCredito dataCredito"/>

                </p:selectOneMenu>
            </h:panelGroup>
        </h:panelGrid>
        <h:panelGrid columns="1" style="width: 100%">
            <h:panelGroup>
                <h:outputLabel value="Patrimônio" /><br/>
                <p:selectOneMenu value="#{orcamentoBean.orcamento.patrimonio}" 
                                 style="width: 400px">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{orcamentoBean.patrimonios}" />
                    <f:converter converterId="simpleEntityConverter" />
                </p:selectOneMenu>
            </h:panelGroup>
        </h:panelGrid>
        <h:panelGrid columns="1" style="width: 100%">
            <h:panelGroup>
                <h:outputLabel value="VPD" /><br/>
                <p:selectOneMenu value="#{orcamentoBean.orcamento.vpd}" 
                                 style="width: 400px">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{orcamentoBean.vpds}" />
                    <f:converter converterId="simpleEntityConverter" />
                </p:selectOneMenu>
            </h:panelGroup>
        </h:panelGrid>
        <h:panelGrid columns="2" 
                     style="width: 100%"> 
            <h:panelGroup>
                <h:outputLabel value="Tipo de Crédito" /><br/>
                <p:selectOneMenu value="#{orcamentoBean.orcamento.tipoCredito}" 
                                 style="width: 260px">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{orcamentoBean.tiposCredito}" />
                    <f:converter converterId="simpleEntityConverter" />
                    <p:ajax event="change" update="valorDespesa leiCredito dataCredito" />
                </p:selectOneMenu>
            </h:panelGroup>
            <h:panelGroup>
                <h:outputLabel value="Valor Despesa"/><br/>
                <pe:inputNumber id="valorDespesa" value="#{orcamentoBean.orcamento.valorDespesa}" 
                                required="true" requiredMessage="Campo Obrigatório" 
                                symbol="R$" decimalSeparator="," thousandSeparator="." 
                                disabled="#{!orcamentoBean.orcamento.tipoCredito
                                            .descricao.equalsIgnoreCase('ORCAMENTARIO')}"/>
            </h:panelGroup>

        </h:panelGrid>

        <h:panelGrid columns="3" 
                     style="width: 100%">

            <h:panelGroup>
                <h:outputLabel value="Lei de Crédito"/><br/>
                <p:inputText id="leiCredito" value="#{orcamentoBean.orcamento.fichaDespesa}" 
                             style="width: 100px"
                             disabled="#{orcamentoBean.orcamento.tipoCredito
                                         .descricao.equalsIgnoreCase('ORCAMENTARIO')}"/>
            </h:panelGroup>
            <h:panelGroup>
                <h:outputLabel value="Data de Crédito"/><br/>
                <p:calendar id="dataCredito"
                            pattern="dd/MM/yyyy"
                            onkeypress="mascara(this, data)"
                            value="#{orcamentoBean.orcamento.dataCredito}" 
                            showOn="button" 
                            required="true" 
                            requiredMessage="Campo Obrigatório"
                            maxlength="10"
                            disabled="#{orcamentoBean.orcamento.tipoCredito
                                        .descricao.equalsIgnoreCase('ORCAMENTARIO')}"/>
            </h:panelGroup>
            <h:panelGroup>
                <h:outputLabel value="Primária" /><br/>
                <p:selectOneMenu value="#{orcamentoBean.orcamento.primaria}" 
                                 style="width: 125px">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{orcamentoBean.primarias}" />
                    <f:converter converterId="simpleEntityConverter" />
                </p:selectOneMenu>
            </h:panelGroup>
        </h:panelGrid>
    </h:panelGrid>

    <hr/>

    <p:commandButton id="btnGravar" value="Gravar" 
                     actionListener="#{orcamentoBean.adicionarEditarFim}"
                     update="formOrcamento" />

    <p:commandButton value="Cancelar" 
                     actionListener="#{orcamentoBean.cancelar}"
                     immediate="true"/>

</h:form>


